package mysql

import (
	"gorm.io/gorm"
	"onerk4/zg5yk/ordering/common/global"
	"onerk4/zg5yk/ordering/common/model"
)

func QueryTakeoutInfo(id int64) (result *model.Takeout, err error) {
	err = global.DB.Model(&model.Takeout{}).Where("id = ?", id).Limit(1).Find(&result).Error
	return
}

func CreateOrder(m *model.Order) error {
	return global.DB.Create(m).Error
}

func QueryOrderInfo(sn string) (result *model.Order, err error) {
	err = global.DB.Where("order_sn = ?", sn).Limit(1).Find(&result).Error
	return
}

func UpdateOrderSta(sn string, sn2 string, tx *gorm.DB) error {
	return tx.Model(&model.Order{}).Where("order_sn = ?", sn).Limit(1).Update("status", sn2).Error
}

func QueryOrderList(id int64) (result []*model.Order, err error) {
	err = global.DB.Model(&model.Order{}).Order("status desc").Where("uid = ?", id).Find(&result).Error
	return
}
